﻿@{
    var url = Web.Infrastructure.Mvc.FileUpload.UploadManager.UploadUrl;
    var name = Html.NameForModel();
    var id = Html.IdForModel();
}
<img style="width:40px;" class="upload" id="image_@id" src="@(Model == null ? Url.Content("~/Images/default.png") : Model)" />
<input type="text" name="@name" id="@id" value="@Model" style="position:absolute;left:-9999px;" readonly="readonly" />
<input type="button" id="btn_@id" value="选择文件" />
<button type="button" id="rest_@id">删除</button>
<script>
    KindEditor.ready(function (K) {
        var editor = K.editor({
            allowFileManager: false,
            allowImageUpload: true,
            formatUploadUrl: false,
            uploadJson: '@url',
        });
        K('#btn_@id').click(function () {
            editor.loadPlugin('insertfile', function () {
                editor.plugin.fileDialog({
                    fileUrl: K('#@id').val(),
                    clickFn: function (url, title) {
                        K('#@id').val(url);
                        $('#image_@id').attr('src', url);
                        editor.hideDialog();
                    }
                });
            });
        });
    });
    $('#rest_@id').click(function () {
        $('#@id').attr('value', '');
        $('#image_@id').attr('src', '@Url.Content("~/Images/default.png")');
    });
</script>